home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / asmutil / disasm.zip / ASMTUTR4.DOC < prev    next >
Text File  |  1988-06-03  |  5KB  |  108 lines

  1. ;COLORINIT EQU       03H       ;Value to initialize color screen (80x25)
  2. COLORINIT EQU      01H       ;Value to initialize color screen (40X25)
  3. ;
  4. ;         Now, describe our own segment
  5. ;
  6. SETSCRN   SEGMENT             ;Set operating segment for CODE and DATA
  7. ;
  8.           ASSUME CS:SETSCRN,DS:SETSCRN,ES:SETSCRN,SS:SETSCRN    ;All segments
  9. ;
  10.           ORG       100H      ;Begin assembly at standard .COM offset
  11. ;
  12. MAIN      PROC      NEAR      ;COM files use NEAR linkage
  13.           JMP       BEGIN     ;And, it is helpful to put the data first, but
  14. ;                             ;then you must branch around it.
  15. ;
  16. ;         Data used in SETSCRN
  17. ;
  18. CHANGELOC   DD      EQUIP     ;Location of the EQUIP, recorded as far pointer
  19. MONOPROMPT  DB      'Please press the plus ( + ) key.$'    ;User sees on mono
  20. COLORPROMPT DB      'Please press the minus ( - ) key.$'   ;User sees on color
  21.  
  22.  
  23. Several things are illustrated on this page.  First, in addition to titles,
  24. the assembler supports subtitles:  hence the SUBTTL pseudo-op.  Second, the
  25. PAGE pseudo-op can be used to go to a new page in the listing.  You see an
  26. example here of the DSECT-style segment in the "SEGMENT AT 40H".  Here, our
  27. our interest is in correctly describing the location of some data in the
  28. BIOS work area which really is located at segment 40H.
  29.  
  30. You will also see illustrated the EQU instruction, which just gives a sym-
  31. bolic name to a number.  I don't make a fetish of giving a name to every
  32. single number in a program.  I do feel strongly, though, that interrupts
  33. and function codes, where the number is arbitrary and the function being
  34. performed is the thing of interest, should always be given symbolic names.
  35.  
  36. One last new element in this section is the define doubleword (DD) instruc-
  37. tion.  A doubleword constant can refer, as in this case, to a location in
  38. another segment.  The assembler will be happy to use information at its
  39. disposal to properly assemble it.  In this case, the assembler knows that
  40. EQUIP is offset 10 in the segment BIOSDATA which is at 40H.
  41.  
  42.           SUBTTL -- Perform function
  43.           PAGE
  44. BEGIN:    CALL      MONOON                  ;Turn on mono display
  45.           MOV       DX,OFFSET MONOPROMPT          ;GET MONO PROMPT
  46.           MOV       AH,PRTMSG                     ;ISSUE
  47.           INT       DOS                           ;IT
  48.           CALL      COLORON                 ;Turn on color display
  49.           MOV       DX,OFFSET COLORPROMPT         ;GET COLOR PROMPT
  50.           MOV       AH,PRTMSG                     ;ISSUE
  51.           INT       DOS                           ;IT
  52.           MOV       AH,GETKEY               ;Obtain user response
  53.           INT       KBD
  54.           CMP       AL,'+'                  ;Does he want MONO?
  55.           JNZ       NOMONO
  56.  
  57.  
  58. IBM PC Assembly Language Tutorial                                        26
  59.  
  60.  
  61.           CALL      MONOON                  ;yes.  give it to him
  62. NOMONO:   RET
  63. MAIN      ENDP
  64.  
  65.  
  66. The main code section makes use of subroutines to keep the basic flow sim-
  67. ple.  About all that's new to you in this section is the use of the BIOS
  68. interrupt KBD to read a character from the keyboard.
  69.  
  70. Now for the subroutines, MONOON and COLORON:
  71.  
  72.           SUBTTL -- Routines to turn monitors on
  73.           PAGE
  74. MONOON    PROC      NEAR                ;Turn mono on
  75.           LES       DI,CHANGELOC        ;Get location to change
  76.           ASSUME    ES:BIOSDATA         ;TELL ASSEMBLER ABOUT CHANGE TO ES
  77.           OR        EQUIP,MONO
  78.           MOV       AX,MONOINIT         ;Get screen initialization value
  79.           INT       SCREEN              ;Initialize screen
  80.           RET
  81. MONOON    ENDP
  82. COLORON   PROC      NEAR                ;Turn color on
  83.           LES       DI,CHANGELOC        ;Get location to change
  84.           ASSUME    ES:BIOSDATA         ;TELL ASSEMBLER ABOUT CHANGE TO ES
  85.           AND       EQUIP,COLOR
  86.           MOV       AX,COLORINIT        ;Get screen initialization value
  87.           INT       SCREEN              ;Initialize screen
  88.           RET
  89. COLORON   ENDP
  90. SETSCRN   ENDS                          ;End of segment
  91.           END       MAIN                ;End of assembly; execution at MAIN
  92.  
  93.  
  94. The instructions LES and LDS are useful ones for dealing with doubleword
  95. addresses.  The offset is loaded into the operand register and the segment
  96. into ES (for LES) or DS (for LDS).  By telling the assembler, with an
  97. ASSUME, that ES now addresses the BIOSDATA segment, it is able to correctly
  98. assemble the OR and AND instructions which refer to the EQUIP byte.  An ES
  99. segment prefix is added.
  100.  
  101. To understand the action here, you simply need to know that flags in that
  102. particular byte control how the BIOS screen service initializes the adapt-
  103. ers.  BIOS will only work with one adapter at a time; by setting the equip-
  104. ment flags to show one or the other as installed and calling BIOS screen
  105. initialization, we achieve the desired effect.
  106.  
  107. The rest is up to you.
  108.